import { createSlice } from "@reduxjs/toolkit";
import { request } from "@/utils";

const userStore = createSlice({
    name:'user',
    initialState:{
        token:''
    },
    reducers:{
        setToken:(state,actions)=>{
            state.token = actions.payload
        }
    }
})

const {setToken} = userStore.actions
const userReducer = userStore.reducer
const fetchLogin = (loginForm) =>{
    return async (dispatch)=>{
        const res = await request.post('/authorizations',loginForm)
        dispatch(setToken(res.data.token))
    }
}
export {fetchLogin}
export default userReducer